package com.study.core

/**
 * @program: spark2.3.2
 * @author: Zhoujian
 * @date: 2022-06-09 18:53
 * @version: 1.0
 * @description: spark 中计算shuffle key分区的算法
 * */
object HashPartitionTest {
	def main(args: Array[String]): Unit = {

		println(nonNegativeMod("spark".hashCode,4))
		println("spark".hashCode)
	}

	def nonNegativeMod(x: Int, mod: Int): Int = {
		val rawMod = x % mod
		rawMod + (if (rawMod < 0) mod else 0)
	}

}
